package com.chen.nongansampling.adapter;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.chen.nongansampling.R;
import com.chen.nongansampling.bean.AddOperatorBean;
import com.chen.nongansampling.bean.ui.ListviewBean;

import java.util.List;

public class ListviewEditTextAdapter extends BaseAdapter {
    public List<ListviewBean> list;
    private Context activity;
    public AddOperatorBean addOperatorBean;
    public void setActivity(Context activity) {
        this.activity = activity;
    }

    public ListviewEditTextAdapter(List<ListviewBean> list, Context activity) {
        this.list = list;
        this.activity = activity;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        //      if (list.get(position).getComplicated() != null && list.get(position).getComplicated() == true) {
//            Log.d("LayoutInflater","true");
//            View view = LayoutInflater.from(activity).inflate(R.layout.listview_rich_text_item, null);
////            ImageView imageView = (ImageView) view.findViewById(R.id.listview_text_image);
////            TextView data = (TextView) view.findViewById(R.id.listview_text_data);
////            TextView name = (TextView) view.findViewById(R.id.listview_text_name);
////            imageView.setImageResource(list.get(position).getImageSrc());
////            data.setText((String) list.get(position).getData());
////            name.setText(list.get(position).getName());
//            return view;
//
//        }else {
        View view = LayoutInflater.from(activity).inflate(R.layout.listview_edit_item, null);
        ImageView imageView = (ImageView) view.findViewById(R.id.listview_text_image);
        EditText data = (EditText) view.findViewById(R.id.listview_edit_data);
        TextView name = (TextView) view.findViewById(R.id.listview_text_name);
        TextView redStar = (TextView) view.findViewById(R.id.red_stars);
        imageView.setImageResource(list.get(position).getImageSrc());
        //         data.setText((String) list.get(position).getData());
        name.setText(list.get(position).getName());
        //设置editview的text属相

        if(list.get(position).getData()!=null){
            data.setText(list.get(position).getData().toString());
        }else{
            data.setText("");
        }

        if (list.get(position).getRedStar()!=null&&list.get(position).getRedStar())
        {
            redStar.setVisibility(View.VISIBLE);
        }
        data.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                list.get(position).setData(s.toString());

            }
        });
        return view;
//        }

        //   return null;
        //    }

    }
//    public String  getEditText(int position) {
//        r
//                getView(position,activity,false);
//                eturn ;
//    }
}


